package org.durcframework.autocode.generator.oracle;

import java.util.Map;

import org.durcframework.autocode.generator.ColumnSelector;
import org.durcframework.autocode.generator.DataBaseConfig;
import org.durcframework.autocode.generator.TableDefinition;
import org.durcframework.autocode.generator.TableSelector;

public class OracleTableSelector  extends TableSelector {

	public OracleTableSelector(ColumnSelector columnSelector, DataBaseConfig dataBaseConfig) {
		super(columnSelector, dataBaseConfig);
	}


	@Override
	protected String getShowTablesSQL(String dbName) {
		return new StringBuilder()
				.append("SELECT ")
				.append("	T1.TABLE_NAME AS NAME,")
				.append("	T2.COMMENTS ")
				.append("FROM")
				.append("	USER_TABLES T1 ")
				.append("LEFT JOIN USER_TAB_COMMENTS T2 ON T1.TABLE_NAME = T2.TABLE_NAME	")
				.append("WHERE")
				.append("	T1.TABLESPACE_NAME = '"+dbName+"' ")
				.append("	AND T1.STATUS = 'VALID'")
				.toString();
	}

	@Override
	protected TableDefinition buildTableDefinition(Map<String, Object> tableMap) {
		TableDefinition tableDefinition = new TableDefinition();
		tableDefinition.setTableName((String)tableMap.get("NAME"));
		tableDefinition.setComment((String)tableMap.get("COMMENTS"));
		return tableDefinition;
	}


}
